package com.nidu.demo.common.enums;

import cn.hutool.core.util.ArrayUtil;
import com.nidu.demo.common.validation.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum GenderEnum implements IntArrayValuable {
    UNKNOWN(0, "未知"),
    MALE(1, "男"),
    FEMALE(2,"女");

    private final Integer value;
    private final String desc;

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(GenderEnum::getValue).toArray();

    @Override
    public int[] array() {
        return ARRAYS;
    }

    public GenderEnum of(Integer val){
        return ArrayUtil.firstMatch(o -> o.getValue().equals(val), values());
    }
}
